<script>
	import { getConfig } from './api';
	import system from './utils/system';

	export default {
		globalData: {
		    statusBarHeight: 0,
		    navHeight: 44,
		    navigationBarHeight: 44,
			bottomHeight: 0,
			showTitle: true
		},
		onLaunch: async function () {
			console.log('App Launch')
			const systemInfo = uni.getSystemInfoSync();
			// #ifdef H5
			uni.hideTabBar();
			this.globalData.platform = 'H5';
			this.globalData.version = systemInfo.appVersion;
			// #endif
			this.globalData.statusBarHeight = systemInfo.statusBarHeight;
			if (systemInfo.safeAreaInsets) {
				this.globalData.bottomHeight = systemInfo.safeAreaInsets.bottom;
			}
			// #ifdef H5
			this.globalData.statusBarHeight = 20;
			// #endif
			
			// #ifdef MP-ALIPAY
			this.globalData.showTitle = false;
			this.globalData.navigationBarHeight = false;
			this.globalData.statusBarHeight = 0;
			this.globalData.navHeight = 0;
			this.globalData.platform = 'MP-ALIPAY';
			this.globalData.version = systemInfo.appVersion;
			// #endif
		 
			// #ifdef MP-WEIXIN
			const custom = wx.getMenuButtonBoundingClientRect();
			this.globalData.navigationBarHeight = custom.height + (custom.top - this.globalData.statusBarHeight) * 2;
			this.globalData.navHeight = this.globalData.navigationBarHeight + this.globalData.statusBarHeight;
			
			this.globalData.platform = 'MP-WEIXIN';
			this.globalData.version = systemInfo.appVersion;
			// #endif
			
			// #ifdef APP
			this.globalData.platform = 'APP';
			this.globalData.version = systemInfo.appVersion;
			// #endif
			
			system.set(this.globalData.platform, this.globalData.version);
			await this.loadConfig();
			
			console.log("版本号：", this.globalData.version);
		},
		onShow: function() {
			console.log('App Show')
			this.loadConfig();
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods: {
			async loadConfig() {
				const res = await getConfig(this.globalData.platform, this.globalData.version);
				this.data = res.data;
				this.$store.state.onlineAudit = this.data.online_audit;
				this.$store.state.kefu = this.data.kefu;
			}
		}
	}
</script>

<style lang="scss">
	@import "@/uni_modules/uview-ui/index.scss";
	
	body {
		background-color: $bg-color;
	}
	
	uni-page-body {
	    display: flex;
	    flex-direction: column;
	    background-color: $bg-color;
	}
	
	.content {
	    height: 100vh;
	    background-color: $bg-color;
	}
	
	.u-tabbar .u-icon__icon {
		font-size: 24px !important;
	}
	
	.flex-b {
	    display: flex;
	    justify-content: space-between;
	}
	
	.flex-a {
	    display: flex;
	}
	
	.flex-ar {
		display: flex;
		justify-content: space-around;
	}
	
	.flex-ct {
		display: flex;
		align-items: center;
	}
</style>
